{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "data = pd.read_csv(r\"data/test.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "      <th>customer_months</th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>policy_deductable</th>\n",
       "      <th>policy_annual_premium</th>\n",
       "      <th>umbrella_limit</th>\n",
       "      <th>insured_zip</th>\n",
       "      <th>...</th>\n",
       "      <th>bodily_injuries</th>\n",
       "      <th>witnesses</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>total_claim_amount</th>\n",
       "      <th>injury_claim</th>\n",
       "      <th>property_claim</th>\n",
       "      <th>vehicle_claim</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "      <th>auto_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "      <td>60</td>\n",
       "      <td>473</td>\n",
       "      <td>2002-12-17</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1134.96</td>\n",
       "      <td>0</td>\n",
       "      <td>445975</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>?</td>\n",
       "      <td>53253</td>\n",
       "      <td>5212</td>\n",
       "      <td>10251</td>\n",
       "      <td>39503</td>\n",
       "      <td>Saab</td>\n",
       "      <td>95</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>301288</td>\n",
       "      <td>36</td>\n",
       "      <td>173</td>\n",
       "      <td>1994-01-15</td>\n",
       "      <td>B</td>\n",
       "      <td>100/300</td>\n",
       "      <td>1000</td>\n",
       "      <td>916.20</td>\n",
       "      <td>0</td>\n",
       "      <td>469238</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>69401</td>\n",
       "      <td>8309</td>\n",
       "      <td>8439</td>\n",
       "      <td>50012</td>\n",
       "      <td>Mercedes</td>\n",
       "      <td>ML350</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>212001</td>\n",
       "      <td>36</td>\n",
       "      <td>147</td>\n",
       "      <td>1995-12-19</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1175.74</td>\n",
       "      <td>5000000</td>\n",
       "      <td>595953</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>63919</td>\n",
       "      <td>5572</td>\n",
       "      <td>11477</td>\n",
       "      <td>42801</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>Neon</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>797680</td>\n",
       "      <td>24</td>\n",
       "      <td>71</td>\n",
       "      <td>1992-06-20</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>500</td>\n",
       "      <td>1472.40</td>\n",
       "      <td>0</td>\n",
       "      <td>613103</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>63173</td>\n",
       "      <td>12027</td>\n",
       "      <td>6500</td>\n",
       "      <td>43423</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>RAM</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>789334</td>\n",
       "      <td>39</td>\n",
       "      <td>230</td>\n",
       "      <td>1996-11-28</td>\n",
       "      <td>C</td>\n",
       "      <td>250/500</td>\n",
       "      <td>1000</td>\n",
       "      <td>1159.44</td>\n",
       "      <td>4000000</td>\n",
       "      <td>581581</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>8847</td>\n",
       "      <td>904</td>\n",
       "      <td>1786</td>\n",
       "      <td>6138</td>\n",
       "      <td>Accura</td>\n",
       "      <td>RSX</td>\n",
       "      <td>2003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>663065</td>\n",
       "      <td>36</td>\n",
       "      <td>30</td>\n",
       "      <td>1999-08-18</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>2000</td>\n",
       "      <td>1384.15</td>\n",
       "      <td>9000000</td>\n",
       "      <td>593323</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>4507</td>\n",
       "      <td>970</td>\n",
       "      <td>477</td>\n",
       "      <td>3339</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>Neon</td>\n",
       "      <td>2002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>283767</td>\n",
       "      <td>47</td>\n",
       "      <td>285</td>\n",
       "      <td>2009-12-23</td>\n",
       "      <td>C</td>\n",
       "      <td>250/500</td>\n",
       "      <td>500</td>\n",
       "      <td>1590.78</td>\n",
       "      <td>7000000</td>\n",
       "      <td>447235</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>YES</td>\n",
       "      <td>45909</td>\n",
       "      <td>5599</td>\n",
       "      <td>5627</td>\n",
       "      <td>34598</td>\n",
       "      <td>Jeep</td>\n",
       "      <td>Grand Cherokee</td>\n",
       "      <td>1999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>325099</td>\n",
       "      <td>39</td>\n",
       "      <td>256</td>\n",
       "      <td>1999-04-08</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>2000</td>\n",
       "      <td>1265.24</td>\n",
       "      <td>0</td>\n",
       "      <td>592069</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>42293</td>\n",
       "      <td>5773</td>\n",
       "      <td>5491</td>\n",
       "      <td>34805</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>RAM</td>\n",
       "      <td>1997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>465673</td>\n",
       "      <td>35</td>\n",
       "      <td>54</td>\n",
       "      <td>2010-09-08</td>\n",
       "      <td>C</td>\n",
       "      <td>100/300</td>\n",
       "      <td>500</td>\n",
       "      <td>1229.74</td>\n",
       "      <td>0</td>\n",
       "      <td>451451</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>76875</td>\n",
       "      <td>14955</td>\n",
       "      <td>7312</td>\n",
       "      <td>59418</td>\n",
       "      <td>Nissan</td>\n",
       "      <td>Maxima</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>913900</td>\n",
       "      <td>34</td>\n",
       "      <td>154</td>\n",
       "      <td>1990-09-27</td>\n",
       "      <td>C</td>\n",
       "      <td>100/300</td>\n",
       "      <td>500</td>\n",
       "      <td>1744.33</td>\n",
       "      <td>0</td>\n",
       "      <td>462941</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>76269</td>\n",
       "      <td>8260</td>\n",
       "      <td>8354</td>\n",
       "      <td>59141</td>\n",
       "      <td>Honda</td>\n",
       "      <td>Civic</td>\n",
       "      <td>1998</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 37 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     policy_id  age  customer_months policy_bind_date policy_state policy_csl  \\\n",
       "0       681822   60              473       2002-12-17            B   500/1000   \n",
       "1       301288   36              173       1994-01-15            B    100/300   \n",
       "2       212001   36              147       1995-12-19            B   500/1000   \n",
       "3       797680   24               71       1992-06-20            C   500/1000   \n",
       "4       789334   39              230       1996-11-28            C    250/500   \n",
       "..         ...  ...              ...              ...          ...        ...   \n",
       "295     663065   36               30       1999-08-18            B   500/1000   \n",
       "296     283767   47              285       2009-12-23            C    250/500   \n",
       "297     325099   39              256       1999-04-08            C   500/1000   \n",
       "298     465673   35               54       2010-09-08            C    100/300   \n",
       "299     913900   34              154       1990-09-27            C    100/300   \n",
       "\n",
       "     policy_deductable  policy_annual_premium  umbrella_limit  insured_zip  \\\n",
       "0                 1000                1134.96               0       445975   \n",
       "1                 1000                 916.20               0       469238   \n",
       "2                 1000                1175.74         5000000       595953   \n",
       "3                  500                1472.40               0       613103   \n",
       "4                 1000                1159.44         4000000       581581   \n",
       "..                 ...                    ...             ...          ...   \n",
       "295               2000                1384.15         9000000       593323   \n",
       "296                500                1590.78         7000000       447235   \n",
       "297               2000                1265.24               0       592069   \n",
       "298                500                1229.74               0       451451   \n",
       "299                500                1744.33               0       462941   \n",
       "\n",
       "     ... bodily_injuries witnesses police_report_available total_claim_amount  \\\n",
       "0    ...               0         3                       ?              53253   \n",
       "1    ...               0         0                      NO              69401   \n",
       "2    ...               2         0                      NO              63919   \n",
       "3    ...               0         0                      NO              63173   \n",
       "4    ...               0         0                       ?               8847   \n",
       "..   ...             ...       ...                     ...                ...   \n",
       "295  ...               0         1                     YES               4507   \n",
       "296  ...               0         3                     YES              45909   \n",
       "297  ...               0         0                       ?              42293   \n",
       "298  ...               2         0                       ?              76875   \n",
       "299  ...               1         1                     YES              76269   \n",
       "\n",
       "    injury_claim  property_claim  vehicle_claim auto_make      auto_model  \\\n",
       "0           5212           10251          39503      Saab              95   \n",
       "1           8309            8439          50012  Mercedes           ML350   \n",
       "2           5572           11477          42801     Dodge            Neon   \n",
       "3          12027            6500          43423     Dodge             RAM   \n",
       "4            904            1786           6138    Accura             RSX   \n",
       "..           ...             ...            ...       ...             ...   \n",
       "295          970             477           3339     Dodge            Neon   \n",
       "296         5599            5627          34598      Jeep  Grand Cherokee   \n",
       "297         5773            5491          34805     Dodge             RAM   \n",
       "298        14955            7312          59418    Nissan          Maxima   \n",
       "299         8260            8354          59141     Honda           Civic   \n",
       "\n",
       "    auto_year  \n",
       "0        2006  \n",
       "1        2008  \n",
       "2        2009  \n",
       "3        2012  \n",
       "4        2003  \n",
       "..        ...  \n",
       "295      2002  \n",
       "296      1999  \n",
       "297      1997  \n",
       "298      2012  \n",
       "299      1998  \n",
       "\n",
       "[300 rows x 37 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>301288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>212001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>797680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>789334</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>663065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>283767</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>325099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>465673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>913900</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     policy_id\n",
       "0       681822\n",
       "1       301288\n",
       "2       212001\n",
       "3       797680\n",
       "4       789334\n",
       "..         ...\n",
       "295     663065\n",
       "296     283767\n",
       "297     325099\n",
       "298     465673\n",
       "299     913900\n",
       "\n",
       "[300 rows x 1 columns]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 1. 查\n",
    "data['policy_id'] # Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>301288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>212001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>797680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>789334</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>663065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>283767</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>325099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>465673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>913900</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     policy_id\n",
       "0       681822\n",
       "1       301288\n",
       "2       212001\n",
       "3       797680\n",
       "4       789334\n",
       "..         ...\n",
       "295     663065\n",
       "296     283767\n",
       "297     325099\n",
       "298     465673\n",
       "299     913900\n",
       "\n",
       "[300 rows x 1 columns]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[['policy_id']] # DataFrame 只有一列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>301288</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>212001</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>797680</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>789334</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>663065</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>283767</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>325099</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>465673</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>913900</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     policy_id  age\n",
       "0       681822   60\n",
       "1       301288   36\n",
       "2       212001   36\n",
       "3       797680   24\n",
       "4       789334   39\n",
       "..         ...  ...\n",
       "295     663065   36\n",
       "296     283767   47\n",
       "297     325099   39\n",
       "298     465673   35\n",
       "299     913900   34\n",
       "\n",
       "[300 rows x 2 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[['policy_id','age']] # DataFrame 有多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "      <th>customer_months</th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>policy_deductable</th>\n",
       "      <th>policy_annual_premium</th>\n",
       "      <th>umbrella_limit</th>\n",
       "      <th>insured_zip</th>\n",
       "      <th>...</th>\n",
       "      <th>property_damage</th>\n",
       "      <th>bodily_injuries</th>\n",
       "      <th>witnesses</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>total_claim_amount</th>\n",
       "      <th>injury_claim</th>\n",
       "      <th>property_claim</th>\n",
       "      <th>vehicle_claim</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "      <td>60</td>\n",
       "      <td>473</td>\n",
       "      <td>2002-12-17</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1134.96</td>\n",
       "      <td>0</td>\n",
       "      <td>445975</td>\n",
       "      <td>...</td>\n",
       "      <td>?</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>?</td>\n",
       "      <td>53253</td>\n",
       "      <td>5212</td>\n",
       "      <td>10251</td>\n",
       "      <td>39503</td>\n",
       "      <td>Saab</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>301288</td>\n",
       "      <td>36</td>\n",
       "      <td>173</td>\n",
       "      <td>1994-01-15</td>\n",
       "      <td>B</td>\n",
       "      <td>100/300</td>\n",
       "      <td>1000</td>\n",
       "      <td>916.20</td>\n",
       "      <td>0</td>\n",
       "      <td>469238</td>\n",
       "      <td>...</td>\n",
       "      <td>?</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>69401</td>\n",
       "      <td>8309</td>\n",
       "      <td>8439</td>\n",
       "      <td>50012</td>\n",
       "      <td>Mercedes</td>\n",
       "      <td>ML350</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2 rows × 36 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   policy_id  age  customer_months policy_bind_date policy_state policy_csl  \\\n",
       "0     681822   60              473       2002-12-17            B   500/1000   \n",
       "1     301288   36              173       1994-01-15            B    100/300   \n",
       "\n",
       "   policy_deductable  policy_annual_premium  umbrella_limit  insured_zip  ...  \\\n",
       "0               1000                1134.96               0       445975  ...   \n",
       "1               1000                 916.20               0       469238  ...   \n",
       "\n",
       "  property_damage bodily_injuries witnesses police_report_available  \\\n",
       "0               ?               0         3                       ?   \n",
       "1               ?               0         0                      NO   \n",
       "\n",
       "  total_claim_amount  injury_claim  property_claim vehicle_claim auto_make  \\\n",
       "0              53253          5212           10251         39503      Saab   \n",
       "1              69401          8309            8439         50012  Mercedes   \n",
       "\n",
       "  auto_model  \n",
       "0         95  \n",
       "1      ML350  \n",
       "\n",
       "[2 rows x 36 columns]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rows = data.iloc[0:2,0:-1] ## 0:2 代表行，从0行开始，2行截至   0:-1  代表列，0行开始，倒数第一行截至\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "      <th>customer_months</th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>policy_deductable</th>\n",
       "      <th>policy_annual_premium</th>\n",
       "      <th>umbrella_limit</th>\n",
       "      <th>insured_zip</th>\n",
       "      <th>...</th>\n",
       "      <th>bodily_injuries</th>\n",
       "      <th>witnesses</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>total_claim_amount</th>\n",
       "      <th>injury_claim</th>\n",
       "      <th>property_claim</th>\n",
       "      <th>vehicle_claim</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "      <th>auto_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "      <td>60</td>\n",
       "      <td>473</td>\n",
       "      <td>2002-12-17</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1134.96</td>\n",
       "      <td>0</td>\n",
       "      <td>445975</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>?</td>\n",
       "      <td>53253</td>\n",
       "      <td>5212</td>\n",
       "      <td>10251</td>\n",
       "      <td>39503</td>\n",
       "      <td>Saab</td>\n",
       "      <td>95</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>301288</td>\n",
       "      <td>36</td>\n",
       "      <td>173</td>\n",
       "      <td>1994-01-15</td>\n",
       "      <td>B</td>\n",
       "      <td>100/300</td>\n",
       "      <td>1000</td>\n",
       "      <td>916.20</td>\n",
       "      <td>0</td>\n",
       "      <td>469238</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>69401</td>\n",
       "      <td>8309</td>\n",
       "      <td>8439</td>\n",
       "      <td>50012</td>\n",
       "      <td>Mercedes</td>\n",
       "      <td>ML350</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2 rows × 37 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   policy_id  age  customer_months policy_bind_date policy_state policy_csl  \\\n",
       "0     681822   60              473       2002-12-17            B   500/1000   \n",
       "1     301288   36              173       1994-01-15            B    100/300   \n",
       "\n",
       "   policy_deductable  policy_annual_premium  umbrella_limit  insured_zip  ...  \\\n",
       "0               1000                1134.96               0       445975  ...   \n",
       "1               1000                 916.20               0       469238  ...   \n",
       "\n",
       "  bodily_injuries witnesses police_report_available total_claim_amount  \\\n",
       "0               0         3                       ?              53253   \n",
       "1               0         0                      NO              69401   \n",
       "\n",
       "  injury_claim  property_claim  vehicle_claim auto_make auto_model auto_year  \n",
       "0         5212           10251          39503      Saab         95      2006  \n",
       "1         8309            8439          50012  Mercedes      ML350      2008  \n",
       "\n",
       "[2 rows x 37 columns]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rows = data.iloc[0:2]  ## 后面不写，列，默认选中全部列\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>301288</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>212001</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>797680</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>789334</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>663065</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>283767</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>325099</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>465673</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>913900</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     policy_id  age\n",
       "0       681822   60\n",
       "1       301288   36\n",
       "2       212001   36\n",
       "3       797680   24\n",
       "4       789334   39\n",
       "..         ...  ...\n",
       "295     663065   36\n",
       "296     283767   47\n",
       "297     325099   39\n",
       "298     465673   35\n",
       "299     913900   34\n",
       "\n",
       "[300 rows x 2 columns]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rows = data.iloc[:,0:2]  ## 前面加逗号，：代表全部行\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>age</th>\n",
       "      <th>policy_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>60</td>\n",
       "      <td>681822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>36</td>\n",
       "      <td>301288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>36</td>\n",
       "      <td>212001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   age  policy_id\n",
       "0   60     681822\n",
       "1   36     301288\n",
       "2   36     212001"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rows = data.loc[0:2,['age','policy_id']]  ##loc 只能使用标签，不能使用索引\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "      <th>customer_months</th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>policy_deductable</th>\n",
       "      <th>policy_annual_premium</th>\n",
       "      <th>umbrella_limit</th>\n",
       "      <th>insured_zip</th>\n",
       "      <th>...</th>\n",
       "      <th>bodily_injuries</th>\n",
       "      <th>witnesses</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>total_claim_amount</th>\n",
       "      <th>injury_claim</th>\n",
       "      <th>property_claim</th>\n",
       "      <th>vehicle_claim</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "      <th>auto_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "      <td>60</td>\n",
       "      <td>473</td>\n",
       "      <td>2002-12-17</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1134.96</td>\n",
       "      <td>0</td>\n",
       "      <td>445975</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>?</td>\n",
       "      <td>53253</td>\n",
       "      <td>5212</td>\n",
       "      <td>10251</td>\n",
       "      <td>39503</td>\n",
       "      <td>Saab</td>\n",
       "      <td>95</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>301288</td>\n",
       "      <td>36</td>\n",
       "      <td>173</td>\n",
       "      <td>1994-01-15</td>\n",
       "      <td>B</td>\n",
       "      <td>100/300</td>\n",
       "      <td>1000</td>\n",
       "      <td>916.20</td>\n",
       "      <td>0</td>\n",
       "      <td>469238</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>69401</td>\n",
       "      <td>8309</td>\n",
       "      <td>8439</td>\n",
       "      <td>50012</td>\n",
       "      <td>Mercedes</td>\n",
       "      <td>ML350</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>212001</td>\n",
       "      <td>36</td>\n",
       "      <td>147</td>\n",
       "      <td>1995-12-19</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1175.74</td>\n",
       "      <td>5000000</td>\n",
       "      <td>595953</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>63919</td>\n",
       "      <td>5572</td>\n",
       "      <td>11477</td>\n",
       "      <td>42801</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>Neon</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 37 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   policy_id  age  customer_months policy_bind_date policy_state policy_csl  \\\n",
       "0     681822   60              473       2002-12-17            B   500/1000   \n",
       "1     301288   36              173       1994-01-15            B    100/300   \n",
       "2     212001   36              147       1995-12-19            B   500/1000   \n",
       "\n",
       "   policy_deductable  policy_annual_premium  umbrella_limit  insured_zip  ...  \\\n",
       "0               1000                1134.96               0       445975  ...   \n",
       "1               1000                 916.20               0       469238  ...   \n",
       "2               1000                1175.74         5000000       595953  ...   \n",
       "\n",
       "  bodily_injuries witnesses police_report_available total_claim_amount  \\\n",
       "0               0         3                       ?              53253   \n",
       "1               0         0                      NO              69401   \n",
       "2               2         0                      NO              63919   \n",
       "\n",
       "  injury_claim  property_claim  vehicle_claim auto_make auto_model auto_year  \n",
       "0         5212           10251          39503      Saab         95      2006  \n",
       "1         8309            8439          50012  Mercedes      ML350      2008  \n",
       "2         5572           11477          42801     Dodge       Neon      2009  \n",
       "\n",
       "[3 rows x 37 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rows = data.loc[0:2] ## 同样: 后面不带，默认选中全部列\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>age</th>\n",
       "      <th>policy_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>60</td>\n",
       "      <td>681822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>36</td>\n",
       "      <td>301288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>36</td>\n",
       "      <td>212001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>24</td>\n",
       "      <td>797680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>39</td>\n",
       "      <td>789334</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>36</td>\n",
       "      <td>663065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>47</td>\n",
       "      <td>283767</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>39</td>\n",
       "      <td>325099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>35</td>\n",
       "      <td>465673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>34</td>\n",
       "      <td>913900</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     age  policy_id\n",
       "0     60     681822\n",
       "1     36     301288\n",
       "2     36     212001\n",
       "3     24     797680\n",
       "4     39     789334\n",
       "..   ...        ...\n",
       "295   36     663065\n",
       "296   47     283767\n",
       "297   39     325099\n",
       "298   35     465673\n",
       "299   34     913900\n",
       "\n",
       "[300 rows x 2 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rows = data.loc[:,['age','policy_id']] ## 同样:前面加入:，默认选中全部行\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>age</th>\n",
       "      <th>policy_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>60</td>\n",
       "      <td>681822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>36</td>\n",
       "      <td>301288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>36</td>\n",
       "      <td>212001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   age  policy_id\n",
       "0   60     681822\n",
       "1   36     301288\n",
       "2   36     212001"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rows = data.loc[0:2,['age','policy_id']]  ##loc 切片，多列\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "      <th>customer_months</th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>policy_deductable</th>\n",
       "      <th>policy_annual_premium</th>\n",
       "      <th>umbrella_limit</th>\n",
       "      <th>insured_zip</th>\n",
       "      <th>...</th>\n",
       "      <th>bodily_injuries</th>\n",
       "      <th>witnesses</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>total_claim_amount</th>\n",
       "      <th>injury_claim</th>\n",
       "      <th>property_claim</th>\n",
       "      <th>vehicle_claim</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "      <th>auto_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "      <td>10</td>\n",
       "      <td>473</td>\n",
       "      <td>2002-12-17</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1134.96</td>\n",
       "      <td>0</td>\n",
       "      <td>445975</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>?</td>\n",
       "      <td>53253</td>\n",
       "      <td>5212</td>\n",
       "      <td>10251</td>\n",
       "      <td>39503</td>\n",
       "      <td>Saab</td>\n",
       "      <td>95</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>789334</td>\n",
       "      <td>10</td>\n",
       "      <td>230</td>\n",
       "      <td>1996-11-28</td>\n",
       "      <td>C</td>\n",
       "      <td>250/500</td>\n",
       "      <td>1000</td>\n",
       "      <td>1159.44</td>\n",
       "      <td>4000000</td>\n",
       "      <td>581581</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>8847</td>\n",
       "      <td>904</td>\n",
       "      <td>1786</td>\n",
       "      <td>6138</td>\n",
       "      <td>Accura</td>\n",
       "      <td>RSX</td>\n",
       "      <td>2003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>753093</td>\n",
       "      <td>10</td>\n",
       "      <td>258</td>\n",
       "      <td>2006-12-08</td>\n",
       "      <td>B</td>\n",
       "      <td>250/500</td>\n",
       "      <td>500</td>\n",
       "      <td>1242.43</td>\n",
       "      <td>0</td>\n",
       "      <td>433689</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>60579</td>\n",
       "      <td>5386</td>\n",
       "      <td>10383</td>\n",
       "      <td>41953</td>\n",
       "      <td>Volkswagen</td>\n",
       "      <td>Jetta</td>\n",
       "      <td>2011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>644825</td>\n",
       "      <td>10</td>\n",
       "      <td>223</td>\n",
       "      <td>2009-04-13</td>\n",
       "      <td>A</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>500</td>\n",
       "      <td>1261.03</td>\n",
       "      <td>0</td>\n",
       "      <td>459954</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>NO</td>\n",
       "      <td>54835</td>\n",
       "      <td>5614</td>\n",
       "      <td>5369</td>\n",
       "      <td>42867</td>\n",
       "      <td>BMW</td>\n",
       "      <td>M5</td>\n",
       "      <td>2011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>770514</td>\n",
       "      <td>10</td>\n",
       "      <td>345</td>\n",
       "      <td>2009-12-12</td>\n",
       "      <td>A</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>500</td>\n",
       "      <td>1270.97</td>\n",
       "      <td>0</td>\n",
       "      <td>637274</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>49400</td>\n",
       "      <td>5060</td>\n",
       "      <td>9890</td>\n",
       "      <td>35350</td>\n",
       "      <td>Chevrolet</td>\n",
       "      <td>Silverado</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>290</th>\n",
       "      <td>870334</td>\n",
       "      <td>10</td>\n",
       "      <td>341</td>\n",
       "      <td>1993-10-03</td>\n",
       "      <td>A</td>\n",
       "      <td>100/300</td>\n",
       "      <td>2000</td>\n",
       "      <td>1299.29</td>\n",
       "      <td>0</td>\n",
       "      <td>622445</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>NO</td>\n",
       "      <td>53224</td>\n",
       "      <td>5605</td>\n",
       "      <td>11144</td>\n",
       "      <td>37567</td>\n",
       "      <td>Mercedes</td>\n",
       "      <td>C300</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>293</th>\n",
       "      <td>150112</td>\n",
       "      <td>10</td>\n",
       "      <td>344</td>\n",
       "      <td>2001-05-06</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>500</td>\n",
       "      <td>1279.77</td>\n",
       "      <td>0</td>\n",
       "      <td>573535</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>NO</td>\n",
       "      <td>5984</td>\n",
       "      <td>943</td>\n",
       "      <td>993</td>\n",
       "      <td>4453</td>\n",
       "      <td>Ford</td>\n",
       "      <td>Fusion</td>\n",
       "      <td>2011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>294</th>\n",
       "      <td>936492</td>\n",
       "      <td>10</td>\n",
       "      <td>270</td>\n",
       "      <td>2006-07-09</td>\n",
       "      <td>A</td>\n",
       "      <td>250/500</td>\n",
       "      <td>500</td>\n",
       "      <td>1398.53</td>\n",
       "      <td>0</td>\n",
       "      <td>596084</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>NO</td>\n",
       "      <td>45536</td>\n",
       "      <td>4740</td>\n",
       "      <td>8938</td>\n",
       "      <td>31842</td>\n",
       "      <td>Audi</td>\n",
       "      <td>A5</td>\n",
       "      <td>2007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>283767</td>\n",
       "      <td>10</td>\n",
       "      <td>285</td>\n",
       "      <td>2009-12-23</td>\n",
       "      <td>C</td>\n",
       "      <td>250/500</td>\n",
       "      <td>500</td>\n",
       "      <td>1590.78</td>\n",
       "      <td>7000000</td>\n",
       "      <td>447235</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>YES</td>\n",
       "      <td>45909</td>\n",
       "      <td>5599</td>\n",
       "      <td>5627</td>\n",
       "      <td>34598</td>\n",
       "      <td>Jeep</td>\n",
       "      <td>Grand Cherokee</td>\n",
       "      <td>1999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>325099</td>\n",
       "      <td>10</td>\n",
       "      <td>256</td>\n",
       "      <td>1999-04-08</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>2000</td>\n",
       "      <td>1265.24</td>\n",
       "      <td>0</td>\n",
       "      <td>592069</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>42293</td>\n",
       "      <td>5773</td>\n",
       "      <td>5491</td>\n",
       "      <td>34805</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>RAM</td>\n",
       "      <td>1997</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>148 rows × 37 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     policy_id  age  customer_months policy_bind_date policy_state policy_csl  \\\n",
       "0       681822   10              473       2002-12-17            B   500/1000   \n",
       "4       789334   10              230       1996-11-28            C    250/500   \n",
       "6       753093   10              258       2006-12-08            B    250/500   \n",
       "11      644825   10              223       2009-04-13            A   500/1000   \n",
       "12      770514   10              345       2009-12-12            A   500/1000   \n",
       "..         ...  ...              ...              ...          ...        ...   \n",
       "290     870334   10              341       1993-10-03            A    100/300   \n",
       "293     150112   10              344       2001-05-06            B   500/1000   \n",
       "294     936492   10              270       2006-07-09            A    250/500   \n",
       "296     283767   10              285       2009-12-23            C    250/500   \n",
       "297     325099   10              256       1999-04-08            C   500/1000   \n",
       "\n",
       "     policy_deductable  policy_annual_premium  umbrella_limit  insured_zip  \\\n",
       "0                 1000                1134.96               0       445975   \n",
       "4                 1000                1159.44         4000000       581581   \n",
       "6                  500                1242.43               0       433689   \n",
       "11                 500                1261.03               0       459954   \n",
       "12                 500                1270.97               0       637274   \n",
       "..                 ...                    ...             ...          ...   \n",
       "290               2000                1299.29               0       622445   \n",
       "293                500                1279.77               0       573535   \n",
       "294                500                1398.53               0       596084   \n",
       "296                500                1590.78         7000000       447235   \n",
       "297               2000                1265.24               0       592069   \n",
       "\n",
       "     ... bodily_injuries witnesses police_report_available total_claim_amount  \\\n",
       "0    ...               0         3                       ?              53253   \n",
       "4    ...               0         0                       ?               8847   \n",
       "6    ...               1         0                      NO              60579   \n",
       "11   ...               2         1                      NO              54835   \n",
       "12   ...               2         0                       ?              49400   \n",
       "..   ...             ...       ...                     ...                ...   \n",
       "290  ...               0         3                      NO              53224   \n",
       "293  ...               0         3                      NO               5984   \n",
       "294  ...               1         2                      NO              45536   \n",
       "296  ...               0         3                     YES              45909   \n",
       "297  ...               0         0                       ?              42293   \n",
       "\n",
       "    injury_claim  property_claim  vehicle_claim   auto_make      auto_model  \\\n",
       "0           5212           10251          39503        Saab              95   \n",
       "4            904            1786           6138      Accura             RSX   \n",
       "6           5386           10383          41953  Volkswagen           Jetta   \n",
       "11          5614            5369          42867         BMW              M5   \n",
       "12          5060            9890          35350   Chevrolet       Silverado   \n",
       "..           ...             ...            ...         ...             ...   \n",
       "290         5605           11144          37567    Mercedes            C300   \n",
       "293          943             993           4453        Ford          Fusion   \n",
       "294         4740            8938          31842        Audi              A5   \n",
       "296         5599            5627          34598        Jeep  Grand Cherokee   \n",
       "297         5773            5491          34805       Dodge             RAM   \n",
       "\n",
       "    auto_year  \n",
       "0        2006  \n",
       "4        2003  \n",
       "6        2011  \n",
       "11       2011  \n",
       "12       2008  \n",
       "..        ...  \n",
       "290      2012  \n",
       "293      2011  \n",
       "294      2007  \n",
       "296      1999  \n",
       "297      1997  \n",
       "\n",
       "[148 rows x 37 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 条件查询\n",
    "conditonQuery = data[(data['age'] > 30) & (data['customer_months'] > 200)]  ## 最外层[]代表条件\n",
    "conditonQuery.loc[:,'age'] = 10\n",
    "conditonQuery"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
